home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_se / same_executables.e < prev    next >
Text File  |  1998-12-22  |  3KB  |  115 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class SAME_EXECUTABLES
  17. --
  18. -- Check if two files given as arguments are (quite) the same 
  19. -- executables files.
  20. -- Terminate execution with the corresponding exit status code.
  21. --
  22.  
  23. creation make
  24.  
  25. feature {NONE}
  26.  
  27.    msg1, msg2: STD_FILE_READ;
  28.  
  29. feature
  30.  
  31.    make is
  32.       local
  33.      path1, path2: STRING;
  34.       do
  35.      if argument_count < 2 then
  36.         io.put_string("usage: same_files <path1> <path2>%N");
  37.         die_with_code(exit_failure_code);
  38.      end;
  39.      path1 := argument(1);
  40.      path2 := argument(2);
  41.      exists(path1);
  42.      exists(path2);
  43.      if same_executables(path1,path2) then
  44.         io.put_string("Sames files.%N");
  45.      else
  46.         io.put_string("Files differ.%N");
  47.         die_with_code(exit_failure_code);
  48.      end;
  49.       end;
  50.  
  51. feature {NONE}
  52.  
  53.    same_executables(path1,path2: STRING): BOOLEAN is
  54.       local
  55.          f1, f2: STD_FILE_READ;
  56.          diff_count: INTEGER;
  57.          stop: BOOLEAN;
  58.       do
  59.      from
  60.         !!f1.connect_to(path1);
  61.             if f1.is_connected then
  62.                if not f1.end_of_input then
  63.                   f1.read_character;
  64.                end;
  65.             end;
  66.             !!f2.connect_to(path2);
  67.             if f2.is_connected then
  68.                if not f2.end_of_input then
  69.                   f2.read_character;
  70.                end;
  71.             end;
  72.             diff_count := 4;
  73.      until
  74.             stop
  75.      loop
  76.         if f1.end_of_input then
  77.                if f2.end_of_input then
  78.                   stop := true;
  79.                   Result := true;
  80.                else
  81.                   stop := true;
  82.                   Result := false;
  83.                end;
  84.             elseif f2.end_of_input then
  85.                stop := true;
  86.                Result := false;
  87.             else
  88.                if f1.last_character /= f2.last_character then
  89.                   diff_count := diff_count - 1;
  90.                   if diff_count = 0 then
  91.                      stop := true;
  92.                      Result := false;
  93.                   end;
  94.                end;
  95.                f1.read_character;
  96.                f2.read_character;
  97.             end;
  98.          end;
  99.          f1.disconnect;
  100.          f2.disconnect;
  101.       end;
  102.  
  103.    exists(path: STRING) is
  104.       do
  105.      if not file_exists(path) then
  106.         io.put_string("File : %"");
  107.         io.put_string(path);
  108.         io.put_string("%" not found.%N");
  109.         die_with_code(exit_failure_code);
  110.      end;
  111.       end;
  112.  
  113. end -- SAME_EXECUTABLES
  114.  
  115.